$(document).ready(function(){
	getEmailSubscribe();
});

function getEmailSubscribe(){
	$('#table_list').DataTable({
        dom: '<"top">rt<"bottom"flip><"clear">',
        language: {
            "sUrl":'../static/plugins/datatables/language.json'
        },
        "searching": false,
        "processing": true,
        "serverSide": true,
        ajax:{
            url:'/email-subscribe/get-email-subscribe',
            type:'post',
            data:function(d){
            	d.subscription_time = $('#subscription_time').val();
            },
            error:getError
        },
        aoColumns: [
            { "data": "create_time", "bSortable": false },
            { "data": "username", "bSortable": false },
            { "data": "email", "bSortable": false },
            { "data": "city", "bSortable":false }
        ]
    });
}

function table_list_reload(){
	var table = $('#table_list').DataTable();
    table.ajax.reload();
}

$('#reset_button').on('click',function(){
	var str_date = show();
	$('#subscription_time').val(str_date+' - '+str_date);
	table_list_reload();
});

$('#subscription_time').daterangepicker({
    language:  'zh-CN',
//    timePicker: true,
//    timePickerIncrement: 30,
    format: 'YYYY-MM-DD',
    locale: {
        format: 'YYYY-MM-DD',
        daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
    }
});

function show() {
    var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    return currentdate;
}

function exportEmailSubscribe(){
	var form = $('#email-subscription-select');
	form.submit();
}